<template>
    <div class="lineItem">
        <!-- 打开console.log -->
        <div  class="console" @touchstart="handleOpenConsole"  @touchend="handleCleanConsole">
        </div>
        <div class="schedule">
            <!-- 询价规则，法律条款 -->
            <CrossLine></CrossLine>
            <ul class="mui-table-view mui-table-view-chevron clause">
                <li class="mui-table-view-cell" @tap="intoSafety">
                    <span>账户与安全</span><span class="i-c icon-you-01"></span>
                </li>
                <li class="mui-table-view-cell" @tap="confirmClearCache">
                    <span>清除缓存</span><span  class="i-c icon-you-01"></span>
                </li>
                <li class="mui-table-view-cell" @tap="handleLoginOut">
                    <span>微信注销</span><span  class="i-c icon-you-01"></span>
                </li>
            </ul>
            <CrossLine></CrossLine>
            <ul class="mui-table-view mui-table-view-chevron clause"  @tap="logout">
                <li class="mui-table-view-cell" style="text-align:center;color:#ff6a27;">
                    <span >退出登录</span>
                </li>
            </ul>
        </div>
    </div>
</template>

<script>
    import axios from 'axios'
    import md5 from 'js-md5'
    import CrossLine from '@/components/base/cross-line/cross-line'
    import mui from "static/js/mui"
    import storage from '@/utils/localstorage'
    import { Toast } from 'mint-ui'
    import VConsole from 'vconsole/dist/vconsole.min.js'
        export default {
        components: {
            CrossLine,
        },
        data() {
            return {
                timer: ''
            }
        },
        props: {},
        watch: {},
        methods: {
            //退出登录
            logout() {
                let that = this
                mui.confirm("您确定要退出吗？","",["取消","确定"], function (e) {
                    //有bug
                    /* if(window.plus){
                        var filter = e.index == 0;
                    }
                    else{
                        var filter = e.index == 1;
                    } */
                    if (e.index) {     //索引是1的就是选择的是确认按钮
                        window.localStorage.clear()
                        that.$store.commit('SET_TOKEN','')
                        //清除存储的零时数据
                        that.$store.commit('resetAppData')
                        window.messageSocket.io.disconnect()
                        window.socket.io.disconnect()
						window.socketState = undefined
                        window.msgCount  = undefined
                        //删除所有监听
						for(var listener in window.messageSocket.$events){
							if(listener != undefined){
								window.messageSocket.removeAllListeners(listener);
							}
                        }
                        //删除所有监听
						for(var listener in window.socket.$events){
							if(listener != undefined){
								window.socket.removeAllListeners(listener);
							}
						}
                        Toast("退出成功")
                        that.$router.push({
                            path: "/min",
                        })
                    } else {
                        //console.log('没有退出')
                    }
                },'div')
            },
            //跳转账户与安全
            intoSafety(){
                this.$router.push({
                    path: "/safety",
                })
            },
            //确认清除缓存
            confirmClearCache() {
                let that = this
                mui.confirm("您确定要清除缓存吗？","",["取消","确定"], function (e) {
                    /*  (window.plus){
                        var filter = e.index == 0;
                    }
                    else{
                        var filter = e.index == 1;
                    } */
                    if (e.index) {     //索引是1的就是选择的是确认按钮
                        let user = storage.getLocalstorage('user')
                        let token = storage.getLocalstorage('token')
                        window.localStorage.clear()
                        storage.setLocalstorage('user', user)
                        storage.setLocalstorage('token', token)
                        Toast("清除缓存成功")
                    } else {
                        //console.log('没有删除')
                    }
                },'div')
            },
            //注销三方登录
            handleLoginOut() {
               plus.oauth.getServices(function(services) {
                   for(var i =0; i<services.length;i++) {
                       services[i].logout(function(e){
                           Toast('注销成功！')
                       }, function(e){
                           Toast('注销失败！')
                       })
                   }
               }) 
            },
            handleOpenConsole() {
                var that=this
                this.timer = setTimeout(function () {
                    mui.prompt('请输入调试密码:', '', ['确定'],function() {
                        let console_password = md5(document.querySelector('.mui-popup-input input').value)
                        axios.post('http://hqg.cnupai.com:8082/common/sysFile/checkPassWordDM5',{ "passWord":console_password}).then(res=>{
                            if(res.data.code===200 && res.data.msg==="success"){
                                console.log("hahaha")
                                new VConsole()
                            }else{
                                clearTimeout(that.timer);
                                Toast('对不起！测试密码不正确,您不能使用此项功能')
                            }
                        }).catch(error => {
                            console.log(error)
                        })  
                    },'div');
                }, 5000); //时间 5s
            },
            handleCleanConsole() {
                clearTimeout(this.timer);
            }
        },
        filters: {},
        computed: {},
        created() { },
        mounted() {
            mui.init({
                keyEventBind: {
                backbutton: true  //关闭back按键监听
                }
            })
            mui.back = function () {
                history.go(-1)
            }
        },
        destroyed() { }
    }

</script>

<style lang="scss" scoped>
    .mui-table-view-chevron .mui-table-view-cell {
        padding-right:15px;color:#333333;font-size:0.7rem;
    }
    .i-c{
        float:right;
        font-size:1.1rem;
    }
    .console{
        position: absolute;
        top: 0px;
        width: 30%;
        height: 43px;
        right: 0px;
        z-index: 999;
    }
</style>